package versionAscensor;

import gnu.io.*;

import java.util.Enumeration;

public class DetectarPuerto
{
	private String PORT_NAMES[] = { "/dev/ttyUSB0", "/dev/ttyUSB1",
			"/dev/ttyUSB2", "/dev/ttyUSB3", "/dev/ttyUSB4", "/dev/ttyUSB5",
			"/dev/ttyUSB6", "/dev/ttyUSB7", "/dev/ttyUSB8", "/dev/ttyUSB9" };
	private String[] PuertosEncontrados = new String[20];
	@SuppressWarnings("rawtypes")
	private Enumeration thePorts = null;
	/**
	 * @return A HashSet containing the CommPortIdentifier for all serial ports
	 *         that are not currently being used. Obtiene todos los puertos
	 *         disponible
	 */

	//@SuppressWarnings({ "rawtypes" })
	// public HashSet<CommPortIdentifier> getAvailableSerialPorts()
	public String[] getAvailableSerialPorts()
	{
		// HashSet<CommPortIdentifier> h = new HashSet<CommPortIdentifier>();
		String puertoSerie;
		int posicion = 0;
		//Enumeration thePorts = CommPortIdentifier.getPortIdentifiers();
		thePorts = CommPortIdentifier.getPortIdentifiers();
		while (thePorts.hasMoreElements())
		{
			CommPortIdentifier com = (CommPortIdentifier) thePorts
					.nextElement();

			for (String portName : PORT_NAMES)
			{

				if (com.getName().equals(portName))
				{
					puertoSerie = com.getName();
					PuertosEncontrados[posicion++] = puertoSerie;
					// System.out.println("puerto Encontrado " +
					// PuertosEncontrados[posicion]);
					// posicion++;
				}

			}

		}
		return PuertosEncontrados; // verificar si no esta de mas!

	}//
		// / String cadena = "thelma";

}
